package com.example.moments.repository;

import android.content.Context;

import com.example.moments.App;
import com.example.moments.dao.CommentDao;
import com.example.moments.dao.ContentDao;
import com.example.moments.dao.ImageDao;
import com.example.moments.dao.LikeDao;
import com.example.moments.dao.LinkDao;
import com.example.moments.db.AppDatabase;
import com.example.moments.ssmemo.entity.Content;

import lombok.Data;

@Data
public class Repository {
//    public  static ContentDao contentDao;
//    public  static  CommentDao commentDao;
//    public  static  ImageDao imageDao;
//    public  static  LikeDao likeDao;
//    public  static  LinkDao linkDao;

//    dao 貌似不应该在这里 定义了
//    private ContentDao contentDao;
//    private CommentDao commentDao;
//    private ImageDao imageDao;
//    private LikeDao likeDao;
//    private LinkDao linkDao;

    CommentRepository commentRepository;
    ContentRepository contentRepository;
    ImageRepository imageRepository;
    LikeRepository likeRepository;
    LinkRepository linkRepository;
//    CommentRepository commentRepository;
//    CommentRepository commentRepository;
//    CommentRepository commentRepository;

    AppDatabase database;

    public Repository() {
        initDatabase();
//        不会实例化
//        Repository.commentDao
//        Repository.ge
//        Repository repository=new Repository();
//        repository.getCommentDao().getAll()
    }

    void initDao(){
//        这个好像不是在这里
//        if (contentDao == null) {
//            contentDao = database.contentDao();
//        }
//        if (commentDao == null) {
//            commentDao = database.commentDao();
//        }
//        if (imageDao == null) {
//            imageDao = database.imageDao();
//        }
//        if (likeDao == null) {
//            likeDao = database.likeDao();
//        }
//        if (linkDao == null) {
//            linkDao = database.linkDao();
//        }

    }

    void initDatabase() {
        Context context = App.getContext();
//        database = AppDatabase.getDatabase(getApplicationContext());
        if (database == null) {
            database = AppDatabase.getDatabase(context);
        }

//        CommentRepository commentRepository;
//        ContentRepository contentRepository;
//        ImageRepository imageRepository;
//        LikeRepository likeRepository;
//        LinkRepository linkRepository;
        if(commentRepository==null){
            commentRepository  =new CommentRepository(database.commentDao());
        }
        if(contentRepository==null){
            contentRepository  =new ContentRepository(database.contentDao());
        }
        if(imageRepository==null){
            imageRepository  =new ImageRepository(database.imageDao());
        }
        if(likeRepository==null){
            likeRepository  =new LikeRepository(database.likeDao());
        }
        if(linkRepository==null){
            linkRepository  =new LinkRepository(database.linkDao());
        }


//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }
//        if(commentRepository==null){
//            commentRepository  =new CommentRepository(database.commentDao());
//        }

//        commentRepository=  commentRepository==null?
//                new CommentRepository(database.commentDao()):commentRepository;

//         public abstract ImageDao imageDao();
//         public abstract LikeDao likeDao();
//         public abstract LinkDao linkDao();
//        数据库必然建立在 activity 之上吗
//        contentDao = database.contentDao();
//        commentDao = database.commentDao();
//        Content content = new Content();
//        contentDao.insert()
    }
}
